package top.fyr.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.fyr.entity.Inventory;

import java.util.ArrayList;

/**
 * @author fuyangrong
 * @date 2019/12/18
 */
@RequestMapping("/inventory")
@RestController
public class InventoryController {

    @Autowired
    private MongoTemplate template;


    @GetMapping("/getInventory")
    public Object getInventory() {
        return template.find(Query.query(Criteria.where("size.uom").is("cm")), Inventory.class);
    }

    @GetMapping("/addInventory")
    public void addInventory() {
        Inventory inventory = new Inventory();
        inventory.setItem("test");
        inventory.setQty(76.2);
        inventory.setStatus("E");
        ArrayList<String> strings = new ArrayList<>();
        strings.add("tag1");
        strings.add("tag2");
        inventory.setTag(strings);
        template.insert(inventory);
    }


}
